#region Using

using System;

#endregion

namespace XNgine.Input
{
    public class RepeatInterval
    {
        public static readonly TimeSpan STANDARD_REPEAT_INTERVAL = TimeSpan.FromMilliseconds(10);

        public TimeSpan Interval { get; set; }
        public TimeSpan LastTriggered { get; private set; }
        public TimeSpan Delay { get; set; }
        private bool delay = false;

        public RepeatInterval() : this(STANDARD_REPEAT_INTERVAL){}
        public RepeatInterval(TimeSpan interval) : this(interval, TimeSpan.Zero){}
        private RepeatInterval(TimeSpan interval, TimeSpan delay)
        {
            Interval = interval;
            Delay = delay;
        }

        public bool ShouldTriggerKeyHeld()
        {
            TimeSpan checkTime = XEngine.Instance.GameTime.TotalGameTime;
            bool result = (checkTime - LastTriggered) > Interval;
            if (result)
                Trigger();
            return result;
        }

        public void Trigger()
        {
            LastTriggered = XEngine.Instance.GameTime.TotalGameTime;
        }
    }
}